<?php
function staticTextDiv($contName, $title)
{
	$tables = array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = '*';
	
	$whereClause = 'contName="'.$contName.'"';
	
	$ifExists = SQLRecover($tables, $fields, $whereClause);
	if ($ifExists['queryStatus'] == 'DB Query yielded no results' || $ifExists['queryStatus'] == 'DB Success, no entries')
	{
		$fieldsAll = array();
		$fieldsAll[0] = 'contName';
		$fieldsAll[1] = 'title';
		$fieldsAll[2] = 'contdata';
		$fieldsAll[3] = 'conttype';
		$fieldsAll[4] = 'perPage';
		$fieldsAll[5] = 'dateUpdated';
		
		$values = array();
		$values[0] = $contName;
		$values[1] = $title;
		$values[2] = '<p>if you\'re logged in, click here.</p>';
		$values[3] = 'static';
		$values[4] = '0';
		$values[5] = sqlDateNow();
		
		$create = SQLInsert($tables[0], $fieldsAll, $values);
		
		return '<div id="'.$contName.'">'.$values[2].'</div>';
	}
	else
	{
		$slider = adminContent('<div id="'.$contName.'slider" class="slider">Update Last: '.dateParser(explode("-", $ifExists['dateUpdated'][0])).popOut('javascript:void(0);', 'widget.php?page=content&id='.$ifExists['contentID'][0].'&pages='.get('page'), 'Edit', 'Edit Content', '650', '820').'</div>', '');
		return '<div id="'.$contName.'" onclick="divSlider(\''.$contName.'slider\')">'.$ifExists['contdata'][0].$slider.'</div>';
	}
}

function ifContentNameExists($contName)
{
	$tables=array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = 'contentID';
	
	$whereClause = 'contName="'.$contName.'"';
	
	$ifExists = SQLRecover($tables, $fields, $whereClause);
	
	if ($ifExists['queryStatus'] == 'DB Query yielded no results' || $ifExists['queryStatus'] == 'DB Success, no entries')
	{
		return false;
	}
	else
	{
		return true;
	}
}

function searchContentFor($id, $field)
{
	$tables =array();
	$tables[0] = 'site_content';
	
	$fields = array();
	$fields[0] = $field;
	
	$where = 'contentID="'.$id.'"';
	$data = SQLRecover($tables, $fields, $where);
	
	return $data[$field][0];
}

function updateContent($id, $contentText, $title)
{
	$fields = array();
	$fields[0] = 'contdata';
	$fields[1] = 'dateUpdated';
	$fields[2] = 'title';
	
	$values = array();
	$values[0] = $contentText;
	$values[1] = sqlDateNow();
	$values[2] = $title;
	
	$data = SQLUpdate('site_content', 'contentID="'.$id.'"', $fields, $values);
	return $data;
}

function blogTextContent($contName, $pagination, $displays, $order, $offset)
{
	$checker = ifContentNameExists($contName);
	
	if ($checker == false)
	{
		$fields = array();
		$fields[0] = 'contName';
		$fields[1] = 'title';
		$fields[2] = 'contdata';
		$fields[3] = 'conttype';
		$fields[4] = 'perPage';
		$fields[5] = 'dateUpdated';
		
		$values = array();
		$values[0] = $contName;
		$values[1] = 'First Blog Entry';
		$values[2] = 'This is the first blog entry, there is no entry previously recorded. Click here to edit.';
		$values[3] = 'blog';
		$values[4] = $pagination;
		$values[5] = sqlDateNow();
		
		$data = SQLInsert('site_content', $fields, $values);
		
		return '<div id="'.$contName.'">
			'.$values[2].'
		</div>';
	}
	else
	{
		
		$tables = array();
		$tables[0] = 'site_content';
		
		$fields = array();
		$fields[0] = 'contentID';
		$fields[1] = 'title';
		$fields[2] = 'contdata';
		$fields[3] = 'conttype';
		$fields[4] = 'perPage';
		$fields[5] = 'dateUpdated';
		
		$whereClause = 'contName="'.$contName.'" AND conttype="blog" ORDER BY contentID '.$order;
		
		$data = SQLRecover($tables, $fields, $whereClause);
		if ($displays == 'all')
		{
			$displays = sizeOf($data['contentID']);
		}
		else
		{
			$displays = $pagination+$offset;
		}
		$display = '';
		$j=0;
		for ($i=$offset; $i<$displays; $i++)
		{
			if (!isset($data['title'][$i]))
			{
				break;
			}
			$display .= '
			<div id="'.$contName.$j.'Title" class="'.$contName.'Title">'.$data['title'][$i].'</div>
			<div id="'.$contName.$j.'Content" class="'.$contName.'Content">'.$data['contdata'][$i].'</div>
			<div id="'.$contName.$j.'Date" class="'.$contName.'Date">Updated Last: '.dateParser(explode("-", $data['dateUpdated'][$i])).'</div>';
			$j++;
		}
		
		$slider = adminContent('<div id="'.$contName.'slider" class="slider">Update Last: '.dateParser(explode("-", $data['dateUpdated'][0])).popOut('javascript:void(0);', 'widget.php?page=blog&name='.$contName.'&pages='.get('page'), 'Edit', 'Edit_Content', '500', '600').'</div>');
		
		return '<div id="'.$contName.'" onclick="divSlider(\''.$contName.'slider\')">
			'.$display.$slider.'</div>';
	}
}

function listAllBlogContent($contName)
{
	$tables = array();
	$tables[0] = 'site_content';
	
	$field = array();
	$field[0] = '*';
	
	$whereClause = 'contName="'.$contName.'" ORDER BY contentID DESC';
	
	$data = SQLRecover($tables, $field, $whereClause);
	
	return $data;
}

function createBlogEntry($contName, $title, $contdata)
{
	$data = listAllBlogContent($contName);
	$fields = array();
	$fields[0] = 'contName';
	$fields[1] = 'title';
	$fields[2] = 'contdata';
	$fields[3] = 'conttype';
	$fields[4] = 'perPage';
	$fields[5] = 'dateUpdated';
	
	$values = array();
	$values[0] = $contName;
	$values[1] = $title;
	$values[2] = $contdata;
	$values[3] = 'blog';
	$values[4] = $data['perPage'][0];
	$values[5] = sqlDateNow();
	
	$result = SQLInsert('site_content', $fields, $values);
	
	return $result['queryStatus'];
}
?>